/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:38917
 * Date:2025/4/10
 * Time:18:58
 */
public class Operators {
    public static void main1(String[] args) {
        //1.基本四则运算符
        int a = 25;
        int b = 10;
        int c = a + b;
        System.out.println(c);//35
        int d = a - b;
        System.out.println(d);//15
        int e = a * b;
        System.out.println(e);//250
        int f = a / b;
        System.out.println(f);//2
        int g = a % b;//相当于数学中进行除法后的余数
        System.out.println(g);//5
        //2.赋值运算符
        a = 50;//把50赋值给a变量
        System.out.println(a);
        a += 2;//相当于a = a + 2;
        System.out.println(a);
        a -= 2;//相当于a = a - 2;
        System.out.println(a);
        a *= 2;//相当于a = a * 2;
        System.out.println(a);
        a /= 2;//相当于a = a / 2;
        System.out.println(a);
        //3.自增/减运算符
        a--;//相当于a = a - 1;
        System.out.println(a);
        a++;//相当于a = a + 1;
        System.out.println(a);
        int i = 100;
        System.out.println(i++);//先打印i的值，再++，输出100
        i = 100;
        System.out.println(++i);//先++，再打印i的值，输出101
    }

    public static void main2(String[] args) {
        //关系运算符
        int a = 25;
        int b = 10;
        System.out.println(a == b);//false
        System.out.println(a != b);//true
        System.out.println(a < b);//false
        System.out.println(a > b);//true
        System.out.println(a <= b);//false
        System.out.println(a != b);//true
    }

    public static void main3(String[] args) {
        //逻辑运算符
        int a = 25;
        int b = 10;
        //a == b的结果已经是false时,将不会再处理a / 0 == 0表达式,所以不报错
        System.out.println(a == b && a / 0 == 0);
        //a != b的结果已经是true时,将不会再处理a / 0 == 0表达式,所以不报错
        System.out.println(a != b || a / 0 == 0);
    }

    public static void main4(String[] args) {
        //位运算符
        byte a = 5; //0000 0101
        byte b = 10;//0000 1010
        //  &
        byte c = (byte) (a & b);
        //  |
        byte d = (byte) (a | b);
        System.out.println(c);//0000 0000
        System.out.println(d);//0000 1111
        //  ^
        System.out.println(a ^ b);//0000 1111
        //  ~
        byte e = 127;//0 1111111
        System.out.println(e);
        //计算结果是-128
        System.out.println(~e);//1 0000000
    }

    public static void main5(String[] args) {
        //移位运算符
        // <<
        byte a = 15;//0000 1111
        //向左移一位
        System.out.println(a << 1);//0001 1110

        // >>
        byte b = 15; //0 0001111
        byte c = -15;//原码1 0001111
                     //反码1 1110000
                     //补码1 1110001
        //向右移一位
        System.out.println(b >> 1);//0 0000111
        //原码1 0000111结果是-8
        System.out.println(c >> 1);//补码1 1111000
                                   //反码1 1110111
                                   //原码1 0001000
    }

    public static void main6(String[] args) {
        int a = 25;
        int b = 10;
        //a > b 表达式的结果时true,所以max的值为a
        int max = a > b ? a : b;
        System.out.println(max);
        //a < b 表达式的结果时false,所以min的值为b
        int min = a < b ? a : b;
        System.out.println(min);
    }
}
